package com.mzx.javase.io;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 类描述：字符缓冲输出流测试类
 *
 * @ClassName BufferedWriterTest
 * @Description TODO
 * @Author 马子鑫
 * @Date 2022/7/31 15:57
 * @Version 1.0
 */
public class BufferedWriterTest {
    public static void main(String[] args) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("temp"));
            bw.write("这是通过bufferedWriter写入的数据");
            bw.newLine(); //写入一个空行
            bw.write("哀吾生之须臾");
            bw.newLine();//换行
            bw.write("羡长江之无穷");
            bw.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
